﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="BoolToVisibilityConverter.cs" company="Mar3ek">
//   This code is licensed under the Mozilla Public License 2.0.
//   You can find the full license text at the following address:
//   https://winkee.codeplex.com/license
// </copyright>
// <summary>
//   The boolean to visibility converter.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace WinKee.Converters
{
    using System;
    using System.IO;

    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Data;

    /// <summary>
    /// The boolean to visibility converter.
    /// </summary>
    internal class BoolToVisibilityConverter : IValueConverter
    {
        #region Public Methods and Operators

        /// <summary>
        /// Converts the given boolean value into a visibility value.
        /// </summary>
        /// <param name="value">
        /// The value to convert.
        /// </param>
        /// <param name="targetType">
        /// The target type.
        /// </param>
        /// <param name="parameter">
        /// The parameter.
        /// </param>
        /// <param name="language">
        /// The language.
        /// </param>
        /// <returns>
        /// Visible if the provided value is true, otherwise Collapsed.
        /// </returns>
        /// <exception cref="InvalidDataException">
        /// Thrown when a non-boolean value is provided.
        /// </exception>
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value == null)
            {
                return Visibility.Visible;
            }

            if (!(value is bool))
            {
                throw new InvalidDataException("The value provided to the converter was not a bool value");
            }

            var boolValue = (bool)value;

            return boolValue ? Visibility.Visible : Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}